package com.szj.filter;

import jakarta.servlet.*;
import jakarta.servlet.annotation.WebFilter;
import lombok.extern.slf4j.Slf4j;

import java.io.IOException;

@Slf4j
//@WebFilter(urlPatterns = "/*") //拦截所有请求
public class DemoFilter implements Filter {
    //初始化方法，web服务器启动时，会调用此方法，只执行一次
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        log.info("int 初始化方法 ......");
    }

    //拦截到请求，会执行此方法，执行多次
    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {
        log.info("doFilter 拦截到请求...... 放行前....");
        //放行
        filterChain.doFilter(servletRequest, servletResponse);

        log.info("doFilter 拦截到请求...... 放行后....");
    }

    @Override
    public void destroy() {
        log.info("destroy 销毁方法 .......");
    }
}
